﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import flash.display.*;

    public class GenericProgressBar {

        public static const PLAY_SPEED:int = 1;

        private var m_progressBar:MovieClip;
        private var m_playing:Boolean;
        private var m_percentage:int;
        private var m_frame:int;
        private var m_targetFrame:int;
        private var m_percentageQueue:Array;
        private var m_dialog:SWFDialog;
        private var m_eventType:String;

        public function GenericProgressBar(_arg1:MovieClip, _arg2:SWFDialog=null){
            this.m_percentageQueue = [];
            super();
            this.m_progressBar = _arg1;
            this.m_playing = false;
            this.m_percentage = 0;
            this.m_targetFrame = 0;
            this.m_dialog = _arg2;
            this.m_eventType = "";
            this.m_progressBar.addEventListener(Event.ENTER_FRAME, this.onUpdate);
        }
        public function set eventType(_arg1:String):void{
            this.m_eventType = _arg1;
        }
        public function setPercentage(_arg1:int):void{
            if ((((_arg1 < 0)) || ((_arg1 > 100)))){
                return;
            };
            this.m_percentageQueue.push((this.m_progressBar.totalFrames * (_arg1 * 0.01)));
            if (!this.m_playing){
                this.m_playing = true;
                if (this.m_percentageQueue[0] < this.m_frame){
                    this.m_targetFrame = this.m_progressBar.totalFrames;
                } else {
                    this.m_targetFrame = this.m_percentageQueue.shift();
                };
                if (this.m_percentageQueue[0] == 0){
                    this.m_percentageQueue.shift();
                };
            };
        }
        public function onUpdate(_arg1:Event):void{
            if (!this.m_playing){
                return;
            };
            this.m_frame = ((this.m_frame)>this.m_progressBar.totalFrames) ? this.m_progressBar.totalFrames : this.m_frame;
            if (this.m_frame < this.m_targetFrame){
                this.m_frame = (this.m_frame + PLAY_SPEED);
                this.m_progressBar.gotoAndStop(this.m_frame);
            } else {
                this.m_playing = false;
                if (this.m_frame >= this.m_progressBar.totalFrames){
                    this.m_frame = 0;
                    this.m_progressBar.gotoAndStop(this.m_frame);
                    if (((this.m_dialog) && (!((this.m_eventType == ""))))){
                        _arg1 = new Event(this.m_eventType);
                        this.m_dialog.dispatchEvent(_arg1);
                    };
                };
                if (this.m_percentageQueue.length != 0){
                    if (this.m_percentageQueue[0] < this.m_frame){
                        this.m_targetFrame = this.m_progressBar.totalFrames;
                    } else {
                        this.m_targetFrame = this.m_percentageQueue.shift();
                    };
                    if (this.m_percentageQueue[0] == 0){
                        this.m_percentageQueue.shift();
                    };
                    this.m_playing = true;
                };
            };
        }

    }
}//package Display 
